import BaseStorage from './base-storage'
import CookieStorage from './cookie-storage';
import LocalSessionStorage from './local-session-storage';

const STORAGE_TYPES = {
    'cookie': CookieStorage,
    'localStorage': LocalSessionStorage,
    'sessionStorage': LocalSessionStorage
}
class Storage extends BaseStorage {
    constructor(type, prefix) {
        super(type, prefix);
        let MyClass = STORAGE_TYPES[type] || STORAGE_TYPES.cookie;
        this._storage = new MyClass(type, prefix);
    }

    setItem(name, payload) {
        return this._storage.setItem(name, payload);
    }

    getItem(name, payload) {
        return this._storage.getItem(name, payload);
    }

    removeItem(name) {
        this._storage.removeItem(name);
    }
}

export default Storage;
